<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>array often function</title>
    <style>
        li{
            transition: transform 1s;
        }
    </style>
</head>
<body>
    <div id="app">
        <ul id="list">
            <li>1...</li>
            <li>2...</li>
            <li>3...</li>
            <li>4...</li>
            <li>5...</li>
        </ul>
    </div>
    <script src="./array.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
    <script>
        let arrIns = new ArrayHandle()
        , arrObj = [{name:'ck',userId:1},{name:'gg',userId:2},{name:'mm',userId:3}]
        , arr = arrIns.delValInArray(arrObj,item=>{
            return item.name == 'gg';
        });
        console.log(arr);
        
        function sort(){
            var arr2 = arrIns.shuffle([0,1,2,3,4])
        
            var lis = Array.from($("#list").find('li'));

            var list = $("#list")[0]

            arr2.forEach(function(val){
                list.appendChild(lis[val])
            })            
        }
        sort()
    </script>
    <script>
        const tree1 = [
        {
            name: 'Node 1',
            id: 1,
            children: [
                {
                    name: 'Node 1.1',
                    id: 11,
                    children: [
                        {
                            name: 'Node 1.1.1',
                            id: 111
                        },
                        {
                            name: 'Node 1.1.2',
                            id: 112
                        }
                    ]
                }
            ]
        },
        {
            name: 'Node 2',
            id: 2,
            children: [
                {
                    name: 'Node 2.1',
                    id: 21,
                    children: [
                        {
                            name: 'Node 2.1.1',
                            id: 211
                        },
                        {
                            name: 'Node 2.1.2',
                            id: 212,
                            children: [
                                {
                                    name: 'Node 2.1.2.1',
                                    id: 2121
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            name: 'Node 3',
            id: 3
        }
        ];
        

        function parSubToSimpleTree(nodes,childName,id) {
            nodes = JSON.parse(JSON.stringify(nodes));
            childName = childName || 'children';
            id = id || 'id';
            let level = 0;
            const simpleNodesFn = function(nodes,pId){
                let simpleNodes = [];
                nodes.forEach((node, i)=>{
                    node.isHasChild = false;
                    node.pId = pId;
                    node.level = ++level;
                    simpleNodes.push(node);
                    let childs = node[childName]
                    if(childs && childs.length>0){
                        node.isHasChild = true;
                        level = 10 * level;
                        simpleNodes = simpleNodes.concat(simpleNodesFn(childs,node[id]));
                        level = parseInt(level/10);
                    }
                })
                return simpleNodes;
            }
            ,simpleNodes = simpleNodesFn(nodes,null);
            simpleNodes.forEach(function(node){
                node[childName] && delete node[childName];
            })
            return simpleNodes;
        }

        console.log(parSubToSimpleTree(tree1))
    </script>
</body>
</html>